<?php

include("header.php");
$restoid=null;
if(isset($_GET["nationid"])&isset($_GET["typeid"])){
	$nationid=$_GET["nationid"];
	$typeid=$_GET["typeid"];
}else{
	echo $_GET["nationid"];
	die();
	redirect("index.php");
}
?>

<!--  start product-table ..................................................................................... -->
<form id="mainform" action="">
<?php

// Connect to server and select databse.
mysql_connect(DB_SERVER, DB_USER, DB_PASS)or die("cannot connect");
mysql_select_db(DB_DATABASE)or die("cannot select DB");

if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };
if (isset($_GET["sort"])) { $order_col  = $_GET["sort"]; } else { $order_col='RESTO_NAME_FR'; };

if ($page<0 || ((int)$page != $page)) {
	$message  = 'Invalid page number: ' .$page . "\n";
	die($message);
}

$start_from = ($page-1) * 15;
$sql = "SELECT info_resto.RESTO_ID AS restoid, info_resto.RESTO_NAME_FR AS restoname,
info_resto.RESTO_PIC_LOC AS resto_pic_loc, info_resto.RESTO_INTRO_FR AS resto_intro,
info_resto.RESTO_ADDR AS resto_addr FROM info_resto
WHERE info_resto.RESTO_TYPE_ID =$typeid AND info_resto.RESTO_NATION =$nationid
ORDER BY $order_col ASC LIMIT $start_from, 15";
$rs_result = mysql_query ($sql);

$rs_count_result = mysql_query ("SELECT COUNT(RESTO_ID) FROM info_resto WHERE info_resto.RESTO_TYPE_ID =$typeid AND info_resto.RESTO_NATION =$nationid");
$total_records = mysql_fetch_row($rs_count_result)[0];
$total_pages = ceil($total_records / 15);
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$rs_result) {
	$message  = 'Invalid query: ' . mysql_error() . "\n";
	$message .= 'Whole query: ' . $query;
	die($message);
}
?>
<table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
<tr>
<th><a href="">Picture</a></th>
<th><a href="">Restaurant Name</a></th>
<th><a href="">Restaurant Intro</a></th>
<th><a href="">Restaurant Address</a></th>
<th><a href="">Options</a></th>
</tr>
<?php
while ($row = mysql_fetch_assoc($rs_result)) {
	?>
	<tr>
	<td><?php echo $row['resto_pic_loc']; ?></td>
	<td><?php echo $row['restoname']; ?></td>
	<td><?php echo $row['resto_intro']; ?></td>
	<td><?php echo $row['resto_addr']; ?></td>

	<td class="options-width">
	<a href="reserver.php?restoid=<?php echo $row['restoid']; ?> class="icon-2 info-tooltip"> Réserver</a>
	<a href="coupon.php?restoid=<?php echo $row['restoid']; ?> class="icon-2 info-tooltip"> Coupon</a>
	</td>
	</tr>
	<?php
};
?>
</table>
<!--  end product-table................................... -->
</form>
</div>
<!--  end content-table  -->


<!--  start paging..................................................... -->
<table border="0" cellpadding="0" cellspacing="0" id="paging-table">
<tr>
<td>
<a href="restolist.php?page=1" class="page-far-left">|<<</a>
<a <?php if(($page-1)>=1) echo "href=\"restolist.php?page=".($page-1)."\"" ?> class="page-left"><<</a>
Page <strong><?=$page?></strong> / <?=$total_pages?>
<a <?php if(($page+1)<=$total_pages) echo "href=\"restolist.php?page=".($page+1)."\"" ?> class="page-right">>></a>
<a href="restolist.php?page=<?=$total_pages?>" class="page-far-right">>>|</a>
</td>
<td>
</td>
</tr>
</table>
<!--  end paging................ -->

<div class="clear"></div>

</div>
<!--  end content-table-inner ............................................END  -->
</td>
<td id="tbl-border-right"></td>
</tr>
<tr>
<th class="sized bottomleft"></th>
<td id="tbl-border-bottom">&nbsp;</td>
<th class="sized bottomright"></th>
</tr>
</table>
<div class="clear">&nbsp;</div>

</div>
<!--  end content -->
<div class="clear">&nbsp;</div>
</div>
<!--  end content-outer........................................................END -->
